package main

import (
	"os"
	"os/exec"
	"promsync/cmd"
	"promsync/progress/log"
)

func main() {

	//后台执行判断
	args := os.Args
	daemon := false
	for k, v := range args {
		if v == "-d" {
			daemon = true
			args[k] = ""
		}
	}
	if daemon {
		asyncExec(args...)
		return
	}

	//同步执行
	executor := new(cmd.CommandExecutor)
	err := executor.InitCommand().Execute()
	if err != nil {
		log.Log.Error("创建命令行失败：%s", err)
	}

}

func asyncExec(args ...string) {
	var arg []string
	if len(args) > 1 {
		arg = args[1:]
	}
	command := exec.Command(args[0], arg...)
	command.Env = os.Environ()
	err := command.Start()
	if err != nil {
		panic(err)
	}
}

//func main() {
//	notify := sync.HttpNotify{
//		Url: "http://192.168.173.160:9090/-/reload",
//	}
//
//	notify.Notify()
//}
